﻿using System;
using System.Collections.Generic;
using HiTeachers.Data.Manager;
using HiTeachers.Entities;
using HiTeachers.Interfaces;

namespace HiTeachers.Services
{
    public class NewServices
    {
        //private static readonly INewDao NewDao = NHibernateDaoFactory.Instance.GetDao<INewDao>("news");
        private static readonly INewDao NewDao = NHibernateDaoFactory.Instance.GetNewDao();

        public static New GetNewById(Guid itemId)
        {
            return NewDao.GetById(itemId, false);
        }

        public static New SaveOrUpdate(New news)
        {
            if (Guid.Empty.Equals(news.ID))
                NewDao.Save(news);
            else
                NewDao.SaveOrUpdate(news);

            return news;
        }

        public static void Delete(New news)
        {
            NewDao.Delete(news);
        }

        public static IList<New> GetRelationNews(Guid guid, DateTime aroundDate, int maxItem)
        {
            return NewDao.GetRelationNews(guid, aroundDate, maxItem);
        }

        public static int TotalNumberOfNew()
        {
            return Convert.ToInt32(NewDao.TotalNumberOfNew());
        }

        public static IList<New> GetNews()
        {
            return NewDao.GetAll();
        }

        public static IList<New> GetNews(int maximumRows, int startRowIndex)
        {
            return NewDao.GetNews(maximumRows, startRowIndex);
        }

        public static void DeleteDataItem(Guid ID)
        {
            New news = NewDao.GetById(ID, false);
            NewDao.Delete(news);
        }
    }
}
